let Utils = require("../../framework/js/utils");

require("../../framework/js/aui/components/grid.component");
require("./ui_11/datagrid");

module.exports = {
    template: `
        <div class="anu-subpage" style="width: 100%;">          
<aui-grid ref="grid"></aui-grid> 
<button class="btn btn-info" type="button" @click="search">搜索</button>
<ui-11-grid ref="datagrid"
            @aftersetdata="loadDataDone"
></ui-11-grid>
        </div>
    `,
    data() {
        var ret = {};
        ret.gridRules = window.AUI.customCompoents.get("aui-grid").defineRules({
            "a": "创建时间",
            "b": "不知道的",
            "c": "绝对哈哈"
        });
        return ret;
    },
    mounted() {
        var self = this;
        self.$refs.grid.setRules(self.gridRules);
        self.$refs.grid.setData([
            {
                a: 19922323,
                b: "sdsdsdsdsd",
                c: "sdsds"
            }
        ]);

        self.$refs.datagrid.setRules(self.gridRules);
        self.$refs.datagrid.requestMethods = function () {
            return new Promise(function (resolve, reject) {
                resolve({
                    data: {
                        data: [
                            {
                                a: 19922323,
                                b: "sdsdsdsdsd",
                                c: "sdsds"
                            },
                            {
                                a: 19922323,
                                b: "sdsdsdsdsd",
                                c: "sdsds"
                            }
                        ]
                    }
                });
            });
        };

        rootcontroller.getPage(self).attachChildComponentReady();
    },
    methods: {
        service() {
        },
        search() {
            this.$refs.datagrid.refresh(1).then(function (table, response, data) {
                table.setPagination({
                    perPage: 10,
                    currentPage: 1,
                    pageCount: 3
                });
            });
        },
        loadDataDone(table, response, data) {
            console.log("load done");
        },
        onError(e) {
            console.log('-------------------');
            console.log(e);
            console.log('-------------------');
        }
    }
};